import axios from 'axios';
import { AnyObject } from '@/types/global';

const url = '/adminapi/region/';

export interface DataState {
  id: number | string;
  'created_at'?: string;
  'updated_at'?: string;
  'parent_code': number | string;
  name: string;
  'short_name': string;
  pinyin: string;
  'area_code': number | string;
  'zip_code': number;
  'city_code': number;
  level: number;
  status: 1 | 2 | 90;
}

export interface QueryParams extends Partial<DataState> {
  page: number;
  limit: number;
}

export interface DataListRes {
  data: DataState[];
  total: number;
}

/**
 * 列表
 */
export function apiList(params?: QueryParams) {
  return axios.get<DataListRes>(`${url}list`, { params });
}

/**
 * 详情
 */
export function apiInfo(params: AnyObject) {
  return axios.get(`${url}info`, { params });
}

/**
 * 保存
 */
export function apiSave(data: DataState) {
  return axios.post(`${url}save`, data);
}

/**
 * 删除
 */
export function apiDel(params: AnyObject) {
  return axios.get(`${url}delete`, { params });
}

/**
 * 树状结构
 */
export function apiTree(params?: AnyObject) {
  return axios.post(`${url}tree`, params);
}
